<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String contextPath = request.getContextPath(); %>
<%@ page import="java.util.*" %>
<%@ page import="common.*" %>
<%@ page import ="java.text.NumberFormat" %>
<%
	List<Receipt> list = Receipt.receipt();
%>
<%
Calendar calendar = Calendar.getInstance();

int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DATE);
NumberFormat nfNum = NumberFormat.getNumberInstance();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="<%= contextPath %>/css/receipt.css" type="text/css" />
		<title>納品書発行画面</title>
	</head>
	<body id="receipt">
		<% if (list != null && list.size()>0) {  %>
			<% for (int i=0 ; i<list.size() ; i++) { %>
			<% Receipt r = (Receipt)list.get(i); %>
			<%		Customer cs = Customer.find_by_code(r.getC_code()); %>
		<div class="pageblock">
			<h1>納品書</h1>
			<div id="logimg">	
			　　<img src="<%= contextPath %>/res/makino.jpg" id="img">　	
		　</div>
			<div id="okyaku">
			<p>
					<table border ="5" cellpadding="3" rules="rows">
					<%-- for (Customer cs : list) { --%> 
						<tr>
							<th>　お客様コード　</th>
							<td>　No.<%= r.getC_code() %></td>
						</tr>
						<tr>
							<th>お客様名</th>
							<td>　<%= cs.getName()%>　様</td>
						</tr>
						<tr>
							<th>郵便番号</th>
							<td>　〒<%= cs.getPostcode()%></td>
						</tr>
						<tr>
							<th>住所</th>
							<td>　<%=cs.getAddress()%></td>
						</tr>
						<tr>
							<th>電話番号</th>
							<td>　<%= cs.getTel()%></td>
						</tr>
					</table>
			</p>
			</div>

	
			<div id="bango">
					<table border=0>
						<tr>
							<td>納品番号</td>
							<td>　　No.<%= r.getR_num() %></td>
						</tr>
						<tr>
							<td>受注番号</td>
							<td>　　No.<%= r.getO_num()%></td>
						</tr>
						<tr>
							<td>納品書作成日</td>
							<td>　　<%=r.getWareki() %></td>
						</tr>
					</table>
			</div>
				
			<div id="yotei">
			<p>
					<table border ="5" rules="rows">
						<tr>
							<th>お届け予定日</th>
							<td>　　<%= r.getDeliver()%></td>
						</tr>
					</table>
			</p>
			</div>
			<h3>　</h3>
			<h3>　</h3>
			<div id="kome">
				毎度お買い上げ頂き誠にありがとうございます。<br/>
				下記の通り納品しますのでご査収ください。
			</div>
				
			<div id="meisai">
				<table border=1>
					<tr>
						<th width="50"></th>
						<th width="150" height="23">商品コード</th>
						<th width="450">商品名</th>
						<th width="150">規格</th>
						<th width="150">単価(円)</th>
						<th width="150">注文数(個)</th>
						<th width="200">合計金額(円)</th>
					</tr>
					<%--ここから下は商品明細のループを表示 --%>
					<% List<ReceiptItem> items = r.receipt_item(); %>
					<% for (int j=0 ; j<items.size() ; j++) { %>
						<% ReceiptItem item = items.get(j); %>
					<% Item itm = Item.find_by_code(item.getItem_code()); %>
					<tr>
						<td class="example2"><%=j+1%></td>
						<td class="example2" height="20"><%= item.getItem_code() %></td>
						<td class="example1"><%= itm.getName()%></td>
						<td class="example2"><%=itm.getSize()%></td>
						<td class="example3"><%=nfNum.format(item.getPrice())%>　</td>
						<td class="example3"><%=nfNum.format(item.getOrders())%>　</td>
						<td class="example3"><%=nfNum.format(item.getPrice()*item.getOrders())%>　</td>
					</tr>
					<% } %>
				</table>
			</div>
			
			<div id="goukei">
				<p>
					<table border ="5" >
						<tr>
							<th height="27">合計金額</th>
							<td class="example3"><%=nfNum.format(r.getPrice_total())%>円</td>
						</tr>
						<tr>
							<th height="27">配送料</th>
							<td class="example3"><%=r.getFee()%>円</td>
						</tr>
						<tr>
							<th width="150" height="27">合計請求金額</th>
							<td class="example3" width="200"><%=nfNum.format(r.getPrice_total()+r.getFee())%>円</td>
						</tr>
					</table>
				</p>
			</div>
			<div id="komeimg">	
			　　<img src="<%= contextPath %>/res/rufi.jpg" id="img2">またの御用命をお待ちしております。
		　</div>
	</div>
			<% } %>
		<% } %>
	</body>
</html>
